package net.atomarrow.render;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import net.atomarrow.ioc.ActionContext;

public class HtmlRender extends Render {
	public static final String HTML_STRING = "HTML_STRING";
	
	public HtmlRender() {
	}
	
	@Override
	public void render() {
	    htmlPrintData(getAttr(HTML_STRING));
	}
    private void htmlPrintData(String data){
        if(data==null){
            return;
        }
        PrintWriter out = getResponseWriter();
        out.print(data);
        out.flush();
        out.close();
    }
    /**
     * 得到Response的Writer
     * @return
     */
    protected PrintWriter getResponseWriter() {
        HttpServletResponse response = ActionContext.getContext().getResponse();
        response.setContentType("text/html;charset=UTF-8");
        response.setHeader("Cache-Control", "no-cache");
        try {
            return response.getWriter();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    


}
